package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.OmcOldmanExcrementRecordMapper;
import com.csun.cmny.provider.exceptions.OmcBizException;
import com.csun.cmny.provider.model.domain.OmcOldmanExcrementRecord;
import com.csun.cmny.provider.model.dto.excrement.ExcrementRecordSelectDto;
import com.csun.cmny.provider.model.vo.excrement.ExcrementRecordVo;
import com.csun.cmny.provider.service.OmcOldmanExcrementRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
@Transactional
public class OmcOldmanExcrementRecordServiceImpl extends BaseService<OmcOldmanExcrementRecord> implements OmcOldmanExcrementRecordService {

    @Resource
    private OmcOldmanExcrementRecordMapper excrementRecordMapper;

    @Override
    public List<ExcrementRecordVo> selectExcrementRecord(ExcrementRecordSelectDto excrementRecordSelectDto) {
        return excrementRecordMapper.selectExcrementRecord(excrementRecordSelectDto);
    }

    @Override
    public List<ExcrementRecordVo> selectExcrementRecordByTime(String startTime, String endTime) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date theStartTime=null;
        Date theEndTime=null;
        try {
             theStartTime = simpleDateFormat.parse(startTime);
             theEndTime = simpleDateFormat.parse(endTime);
        } catch (ParseException e) {
            throw new OmcBizException(ErrorCodeEnum.OMC10080021);
        }

        return excrementRecordMapper.selectExcrementRecordByTime(theStartTime,theEndTime);
    }
}
